package com.example.springioc3.controller;

import com.example.springioc3.component.UserComponent;
import com.example.springioc3.model.UserInfo;
import com.example.springioc3.service.UserService;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;

//@Controller
//public class UserController {
//    //注入方法1：属性注入
//    @Autowired
//    private final UserService userService = new UserService();
//    public void sayHi() {
//        userService.doService();
//        System.out.println("hi, UserController");
//    }
//}

//@Controller
//public class UserController {
//    //注入方法2：构造方法注入
//    private UserService userService;
//    private UserComponent userComponent;
////    public UserController(){
////
////    }
//    public UserController(UserService userService) {
//        this.userService = userService;
//    }
//    @Autowired
//    public UserController(UserService userService, UserComponent userComponent) {
//        this.userService = userService;
//        this.userComponent = userComponent;
//    }
//    public void doService() {
//        userComponent.doComponent();
//        userService.doService();
//        System.out.println("do UserController");
//    }
//}

//@Controller
//public class UserController {
//    private UserService userService;
//    @Autowired
//    public void setUserService(UserService userService) {
//        this.userService = userService;
//    }
//    public void doController() {
//        userService.doService();
//        System.out.println("do UserController");
//    }
//}

@Controller
public class UserController {
//    @Qualifier("userInfo2")
    @Resource(name = "userInfo2")
    @Autowired
    private UserInfo userInfo;
//    @Autowired
//    public UserController(UserInfo userInfo1) {
//        this.userInfo = userInfo1;
//    }
//    @Autowired
//    public void setUserInfo(UserInfo userInfo1) {
//        this.userInfo = userInfo1;
//    }
    public void sayHi() {
        System.out.println(userInfo.toString());
        System.out.println("hello, controller");
    }
}